package com.buddy.syn.block._10;

/**
 * 当其他线程执行x对象中synchronized同步方法/this同步代码块时，呈现同步效果
 * 前提是同一个x对象监视器
 */
public class Service {

    public void method(MyObject myObject){
        synchronized (myObject){
            try{
                System.out.println("method ____getLock time="+System.currentTimeMillis()
                        +" run ThreadName="+Thread.currentThread().getName());
                Thread.sleep(5000);
                System.out.println("method releaseLock time="+System.currentTimeMillis()
                        +" run ThreadName="+Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
